#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include<cstring>
#include <queue>
#include<vector>
#include<functional>
using namespace std;

namespace my
{
    template <class T, class Container = std::vector<T>, class Compare = std::less<T>>
    class priority_queue
    {
    public:
        priority_queue() {};
        bool empty() { return c.empty(); }
        size_t size() { return c.size(); }
        const T& top() const
        {
            return c[0];
        }
        void push(const T& x)
        {
            c.push_back(x);
            AdjustUp(c.size() - 1);
        }
        void pop()
        {
            swap(c[0], c[c.size() - 1]);
            c.pop_back();
            AdjustDown(0);
        }
    private:
        void AdjustUp(int child)
        {
            int parent = (child - 1) / 2;
            while (child)
            {
                if (com(c[child], c[parent]))
                {
                    swap(c[child], c[parent]);
                    child = parent;
                    parent = (child - 1) / 2;
                }
                else break;
            }
        }
        void AdjustDown(int parents)
        {
            int child = (parents * 2) + 1;
            while (child < (int)c.size())
            {
                if (child + 1 < (int)c.size() && com(c[child], c[child + 1])) child += 1;
                if (com(c[child], c[parents]))
                {
                    swap(c[child], c[parents]);
                    parents = child;
                    child = (parents * 2) + 1;
                }
                else break;
            }
        }
    private:
        Container c;
        Compare com;
    };
}

int main()
{
    my::priority_queue<int> pq;
    pq.push(60);
    pq.push(10);
    pq.push(30);
    cout << pq.top() << endl;
    pq.pop();
    pq.pop();
    cout << pq.top() << endl;
    return 0;
}
